<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/1/22
  Time: 20:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title> 选择城市 </title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/default/easyui.css" type="text/css"></link>
    <script type="text/javascript" src="plug-in/jquery/jquery-1.8.3.js"></script>
    <link rel="stylesheet" href="plug-in/jquery/css/demo.css" type="text/css">
    <link rel="stylesheet" href="plug-in/jquery/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="plug-in/jquery/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="plug-in/jquery/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="plug-in/tools/Transfer.js"></script>
    <link rel="stylesheet" href="plug-in/tools/css/style.css">
    <link rel="stylesheet" href="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.css">
    <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
    <%--<link rel="stylesheet" href="/plug-in/tools/css/common.css"></link>--%>
    <script type="text/javascript">
        <!--
        var setting = {
            check: {
                enable: true
            }
            // callback: {
            //     onCheck: zTreeOnCheck
            // }
        };

        var zNodes =${trees};

        $(document).ready(function(){
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        });
        var html = "";
        var cityId = "";//用户ID集合
        var cityName = "";//用户名称集合
        var nodes = new Array();
        function zTreeOnCheck(event, treeId, treeNode) {

            //获取选中机构用户节点
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            var childNodes = treeObj.transformToArray(treeNode);
            var city_id = "";
            var city_name  ="";
            for ( var i = 0; i < childNodes.length; i++) {
                var flag = childNodes[i].isParent;
                if (flag==true){
                    continue;
                }else {
                    // city_id+=childNodes[i].id + ",";
                    // city_name += childNodes[i].name+" ";
                    nodes[i] = childNodes[i].id;
                    nodes[i] = childNodes[i].name;
                    html += "<tr id="+childNodes[i].id+"><td><input type='checkbox' value="+childNodes[i].id+" name='ids'/>"+childNodes[i].name+"</td></tr>";
                }

            }
           // alert(city_id);
           //  $.session.set("city_id",city_id);
           //  $.session.set("city_name",city_name);
        };

        function addCity() {
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            // var childNodes = treeObj.transformToArray(treeObj.getCheckedNodes());
            var  childNodes =treeObj.getCheckedNodes(true);
            for ( var i = 0; i < childNodes.length; i++) {
                var flag = childNodes[i].isParent;
                if (flag==true){
                    continue;
                }else {
                    nodes[i] = childNodes[i].id;
                    // nodes[i] = childNodes[i].name;
                    html += "<tr id="+childNodes[i].id+"><td><input type='checkbox' value="+childNodes[i].id+" name='ids'/>"+childNodes[i].name+"</td></tr>";
                }

            }
            // var html = "<tr id="+id+"><td><input type='checkbox' value="+id+">"+name+"</td></tr>";
            $("#checkedCity").append(html);
            $("table [id]").each(function () {
                var ids =   $(this).attr("id");
                if( $("table [id="+ids+"]").length >= 2 ){
                    $("table [id="+ids+"]:not(:first)").remove();
                }
            })
            var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
            treeObj.checkAllNodes(false);
            html = "";
            var h = "";
            var v = "";
            $("#checkedCity tr").each(function (i) {
                $(this).children('td').each(function(j){  // 遍历 tr 的各个 td
                    v += $(this).find("input").val() + ",";
                    h+=$(this).text()+" ";
                });
            })
            $("#fourValue").val(v);
            $("#fourText").val(h);
            cityId = "";
            cityName = "";
        }
        function removeCity() {
            var h = "";
            var v = "";
            var arr = [];
            $("input:checked").each(function () {
                var mesids = $(this).val();
                arr.push(mesids);
            })
            var ids = arr.toString();
            ids = decodeURI(ids);
            var arr1 = ids.split(",");
            for (var i = 0;i<arr1.length;i++){
                $("#"+arr1[i]).remove();
            }
            $("#checkedCity tr").each(function (i) {
                $(this).children('td').each(function(j){  // 遍历 tr 的各个 td
                    v += $(this).find("input").val() + ",";
                    h+=$(this).text()+" ";
                });
            })
            $("#fourValue").val(v);
            $("#fourText").val(h);
            $("#idAll").removeAttr("checked");
        }
        function idAll() {
            $("input[name='ids']").each(function () {
                if ($(this).prop("checked")) {
                    $(this).removeAttr("checked");

                } else {
                    $(this).prop("checked", true);
                }
            })
        }
        function refer() {
            var h = "";
            var v = "";
                $("#checkedCity tr").each(function (i) {
                    $(this).children('td').each(function(j){  // 遍历 tr 的各个 td
                           v += $(this).find("input").val() + ",";
                            h+=$(this).text()+" ";
                      });
                })
            $("#fourValue").val(v);
            $("#fourText").val(h);

            // $("#SL1",top.myWindow.document).html("<span>"+h+"</span>");
            // $("#cityId",top.myWindow.document).val(v);
            frameElement.api.close();
        }
        $(document).ready(function () {
            var ckName =  $.session.get("name");
            if( typeof(ckName)!="undefined"){
                $("#ckName").html(ckName);
            }
            var wlName =  $.session.get("wlName");
            if( typeof(wlName)!="undefined"){
                $("#wlName").html(wlName);
            }
            var ids = $.session.get("ids");
            if( typeof(ids)!="undefined"){
                $.ajax({
                    type:"POST",
                    dataType:"json",
                    data:{"ids":ids},
                    url:"cbsWarehouseController.do?getCityByIds",
                    success:function (data) {
                        if (data.success){
                            var obj = data.obj;
                            if (obj!=null){
                                var html="";
                                var v = "";
                                var h = "";
                                for (i in obj){
                                    html += "<tr id="+obj[i].id+"><td><input type='checkbox' value="+obj[i].id+" name='ids'/>"+obj[i].territoryname+"</td></tr>";
                                }
                                $("#checkedCity").append(html);
                                $("#checkedCity tr").each(function (i) {
                                    $(this).children('td').each(function(j){  // 遍历 tr 的各个 td
                                        v += $(this).find("input").val() + ",";
                                        h+=$(this).text()+" ";
                                    });
                                })
                                $("#fourValue").val(v);
                                $("#fourText").val(h);
                                // $.session.set("city_id",v);
                                // $.session.set("city_name",h);
                                $.session.remove("ids");
                            }
                        }
                    }
                })
            }
        })
        //-->
    </script>
</head>
<%--<ul id="treeDemo" class="ztree"></ul>--%>
<body>
<div class="ty-transfer mt20 ml20" id="ued-transfer-1" style="margin: 10px auto; width: 600px;">
    <div style="margin:10px 0">当前服务等级:SL4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;仓库名称:<span id="ckName">${name}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;物流名称:<span id="wlName">${logistics}</span></div>
    <div class="fl ty-transfer-list transfer-list-left">
        <div class="ty-transfer-list-head">
            待选目的地城市
        </div>
        <div class="ty-transfer-list-body">
            <ul id="treeDemo" class="ztree">
            </ul>
        </div>
        <div class="ty-transfer-list-foot">
            <div class="ty-tree-div">
                <div class="tyc-check-blue fl">
                </div>
            </div>
        </div>
    </div><input type="hidden" id="fourValue"/><input type="hidden" id="fourText"/>
    <div class="fl ty-transfer-operation">
        <span class="ty-transfer-btn-toright to-switch" onclick="addCity()">
            添加
        </span>
        <span class="easyui-linkbutton l-btn" onclick="removeCity()">
            取消
        </span>
    </div>
    <div class="fl ty-transfer-list transfer-list-right">
        <div class="ty-transfer-list-head">
            已选目的地城市
        </div>
        <div class="ty-transfer-list-body">
            <table id="checkedCity">
            </table>
        </div>
        <div class="ty-transfer-list-foot">
            <div class="ty-tree-div">
                <div class="tyc-check-blue fl">
                    <input type="checkbox" id="idAll"  onclick="idAll()">
                    <span>
                    </span>
                </div>
                <div class="ty-tree-text">
                    全选
                </div>
            </div>
        </div>
    </div>
         
</div>
<!--过滤筛选 end-->
<script type="text/javascript" src="plug-in/tools/Transfer.js"></script>
<script type="text/javascript">
    $("#ued-transfer-1").transferItem();
</script>

</body>
</html>
